const mongoose = require('mongoose');

const SourceSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  listUrl: {
    type: String,
    required: true,
    trim: true
  },
  detailUrlPattern: {
    type: String,
    required: false,
    trim: true,
    description: '人员详情页URL模式，如果为空则从列表页解析'
  },
  organization: {
    type: String,
    required: true,
    trim: true
  },
  lastCrawled: {
    type: Date,
    default: null
  },
  status: {
    type: String,
    enum: ['active', 'inactive', 'error'],
    default: 'active'
  },
  errorMessage: {
    type: String,
    default: null
  },
  // 代理设置
  proxy: {
    enabled: {
      type: Boolean,
      default: false
    },
    host: {
      type: String,
      default: '',
      trim: true
    },
    port: {
      type: Number,
      default: 0
    }
  },
  // 采集配置 - 用于定义如何从页面中提取信息
  selectors: {
    listItemSelector: {
      type: String,
      required: false,
      default: '' // 列表项的CSS选择器
    },
    nameSelector: {
      type: String,
      required: false,
      default: '' // 姓名的CSS选择器
    },
    positionSelector: {
      type: String,
      required: false,
      default: '' // 职位的CSS选择器
    },
    imageSelector: {
      type: String,
      required: false,
      default: '' // 图片的CSS选择器
    },
    detailLinkSelector: {
      type: String,
      required: false,
      default: '' // 详情链接的CSS选择器
    }
  },
  createdAt: {
    type: Date,
    default: Date.now
  },
  updatedAt: {
    type: Date,
    default: Date.now
  }
}, { timestamps: true });

module.exports = mongoose.model('Source', SourceSchema); 